package com.kgc.controller;

import com.kgc.exception.QgFinal;
import com.kgc.pojo.User;
import com.kgc.remote.UserRemote;
import com.kgc.util.RedisUtil;
import com.kgc.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class UserController {
    @Autowired
    private UserRemote userRemote;
    @Autowired
    private RedisUtil redisUtil;

    @RequestMapping("LoginByPhone")
    public Object longByPhone(String userName,String password){
        String token = UUID.randomUUID()+"";
        User user = userRemote.longByPhone(userName,password);
        if(user!=null){
            redisUtil.set("TokenId:"+token,user.getId(),30*60);
            redisUtil.set("UserInfo:"+token,user,30*60);
            return new Result(user,QgFinal.GET_USERINFO_SUCCESS);
        }
        return new Result(null,QgFinal.GET_USERINFO_FAIL);
    }
}
